<%@page import="com.googlecode.contests_repo.core.users.AccessRight" %>
<%@page import="com.googlecode.contests_repo.core.config.ConfigurationManager"%>
<%@page import="com.googlecode.contests_repo.core.users.UserManager"%>
<%@page import="com.googlecode.contests_repo.core.model.Series"%>
<%@page import="com.googlecode.contests_repo.core.model.Contest"%>
<%@page import="com.googlecode.contests_repo.core.model.Resource"%>
<%@page import="com.googlecode.contests_repo.core.model.ResourcesUtils"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.io.File"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Series</title>
</head>
<body>
<%@include file='header.jsp'%>
<%
    String seriesTitle = request.getParameter("series");
    String repoPath = ConfigurationManager.getInstance().getRepoRoot();
    String seriesPath = ConfigurationManager.getInstance()
		    .getRepoRoot() + File.separator + seriesTitle;
    String publicFolder = "_public_files";
    String privateFolder = "_files";
    Series series = ResourcesUtils.getJSON(new File(seriesPath));
    String loggedUser = (String) session.getAttribute("username");
%>
	<h1>Series Info</h1>
	<p>
		<font size="4"> <b>Title: </b>  <%=series.getTitle()%> </font>
	</p>
	<p>
		<font size="4"> <b>About: </b> <%=series.getAbout()%> </font>
	</p>
		<%
		    if (UserManager.hasAccessRight(loggedUser, seriesPath,
						    AccessRight.VIEW_FULL))
				    {
		%>
			<p>
				<font size="4"> <b>Notes: </b> <%=series.getNotes()%> </font>
			</p>
			<br />
		<%
		    }
		%>
			<h2>Contests:</h2>
			<table border=1>
				<tr>
					<th>Title</th>
					<th>About</th>
					<th>View</th>
				</tr>
		<%
		    List<Contest> contestList = ResourcesUtils.fetchResources(new File(
						    seriesPath));
				    if (contestList != null)
				    {
						for (Contest contest : contestList)
						{
							if (UserManager.hasAccessRight(loggedUser, seriesPath + File.separator + contest.getTitle(), AccessRight.LIST))
							{
		%>
		<tr>
			<td><%=contest.getTitle()%></td>
			<td><%=contest.getAbout()%></td>
			<td><a
				href="contest.jsp?series=<%=seriesTitle%>&contest=<%=contest.getTitle()%>">details</a>
			</td>
		</tr>
		<%
					}
		    	}
		    }
		%>
	</table>
	<br />
	<h2>Downloads:</h2>
			<table border=1>
				<tr>
					<th>Folder name</th>
					<th>Download</th>
					<th>Browse</th>
				</tr>
				<%
					if(new File(seriesPath + File.separator + publicFolder).exists()){
				%>
				<tr>
					<td><%=publicFolder%></td>
					<td><a
						href="download_folder.jsp?from=series&series=<%=seriesTitle%>&folder=<%=publicFolder%>">download</a>
					</td>
					<td><a
						href="view_folder.jsp?path=<%=URLEncoder.encode(seriesTitle + File.separator + publicFolder, "UTF-8")%>">browse</a>
					</td>
				</tr>
				<%
					}
				    if (new File(seriesPath + File.separator + privateFolder).exists()&&UserManager.hasAccessRight(loggedUser, seriesPath,
								    AccessRight.VIEW_FULL))
						    {
				%>
				<tr>
					<td><%=privateFolder%></td>
					<td><a
						href="download_folder.jsp?from=series&series=<%=seriesTitle%>&folder=<%=privateFolder%>">download</a>
					</td>
					<td>
						<a href="view_folder.jsp?path=<%=URLEncoder.encode(seriesTitle + File.separator + privateFolder, "UTF-8")%>">browse</a>
					</td>
				</tr>
				<%
						    }
				%>
				</table>
	<br />
<a href="series_list.jsp">Back</a>
</body>
</html>